<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">

        <a-row>

          <a-col :span="12">
            <a-form-model-item label="用户" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userId">
              <j-dict-select-tag type="list" v-model="model.userId" dictCode="USER_INFO,USER_UNAME,USER_ID" placeholder="请选择用户" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="学生姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyName">
              <a-input v-model="model.applyName" placeholder="请输入学生姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="学生头像" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyPhoto">
              <j-image-upload isMultiple  v-model="model.applyPhoto" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="报名专业" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="majorId">
              <j-dict-select-tag type="list" v-model="model.majorId" dictCode="MAJOR,MAJOR_NAME,MAJOR_ID" placeholder="请选择报名专业" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="报名时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyTime">
              <j-date placeholder="请选择报名时间"  v-model="model.applyTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="手机号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyPhone">
              <a-input v-model="model.applyPhone" placeholder="请输入手机号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applySex">
              <j-dict-select-tag type="radio" v-model="model.applySex" dictCode="sex" placeholder="请选择性别" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="学历编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="educationId">
              <j-dict-select-tag type="list" v-model="model.educationId" dictCode="EDUCATION,EDU_NAME,EDU_ID" placeholder="请选择学历编号" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="电子邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyEmail">
              <a-input v-model="model.applyEmail" placeholder="请输入电子邮箱"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="QQ号码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyQqnumber">
              <a-input v-model="model.applyQqnumber" placeholder="请输入QQ号码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="身份证" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyIdcard">
              <a-input v-model="model.applyIdcard" placeholder="请输入身份证"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="所学专业" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyOldMajor">
              <a-input v-model="model.applyOldMajor" placeholder="请输入所学专业"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="家庭住址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyAddress">
             <j-area-linkage type="cascader" v-model="model.applyAddress" placeholder="请输入省市区"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item  label="监护人关系" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyGuardian">
              <j-dict-select-tag type="list" v-model="model.applyGuardian" dictCode="apply_guardian" placeholder="请输入监护人姓名"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="监护人电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyFamilyPhone">
              <a-input v-model="model.applyFamilyPhone" placeholder="请输入监护人电话"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ApplyInfoForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
            applyStatusId:"0",
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           applyName: [
              { required: true, message: '请输入学生姓名!'},
           ],
           applyPhone: [
              { required: true, message: '请输入学生电话!'},
              { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码!'},
           ],
          applyEmail: [
            { required: false},
            { pattern: /^([\w]+\.*)([\w]+)@[\w]+\.\w{3}(\.\w{2}|)$/, message: '请输入正确的电子邮件!'},
          ],
          applyQqnumber: [
            { required: false},
            { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!'},
          ],
           applyIdcard: [
              { required: false},
              { pattern: '[1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]', message: '不符合校验规则!'},
           ],
          applyGuardian: [
            { required: true, message: '请选择监护人关系!'},
          ],
           applyFamilyPhone: [
              { required: false},
              { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码!'},
           ],
        },
        url: {
          add: "/applyinfo/applyInfo/add",
          edit: "/applyinfo/applyInfo/edit",
          queryById: "/applyinfo/applyInfo/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>